package springboottest.springboot;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * 
 * @author T440P
 *不指定包默认加了@Controller和@RestController都能控制
 */
@RestControllerAdvice
//@RestControllerAdvice(basePackages="")
public class SpringBootAdvice {
	@ExceptionHandler(value = Exception.class)
	public Map<String, Object> errorHandler(Exception exception) {
		Map<String, Object> map = new HashMap<>();
		map.put("code", 100);
		map.put("message", exception);
		return map;

	}

	@ExceptionHandler(value = MyRuntimeException.class)
	public Map<String, Object> runtimeErrorHandler(MyRuntimeException re) {
		Map<String, Object> map = new HashMap<>();
		map.put("code", re.getCode());
		map.put("message", re.getMessage());
		return map;

	}

}
